<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="cn.school.util.StringKit"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@page import="cn.school.service.*,cn.school.entity.*,java.util.*" %>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>学生信息</title>
<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>

</head>
<body>
<%@include file="checkLogin.jsp" %>
<%-- <div>
 <%
   Object o=session.getAttribute("USER_LOGIN");
   if(o==null){
	   out.print("<script>alert('你丫的是翻窗户进来的？');location.replace('login.jsp');</script>");
	   return;
   }
 %>
 <h1>欢迎你，<%=o%>, <a href="logout.jsp">退出</a></h1>
</div> --%>
<%-- <p>
 <%
 String name=request.getParameter("studentname");
 %>
 您刚才注册的姓名是<%=name%>
</p> --%>
<%
String name=StringKit.convertNull(request.getParameter("sname"));
String tel=StringKit.convertNull(request.getParameter("tel"));
StudentService service=new StudentService();
int pageNo=StringKit.toInt(request.getParameter("pageNo"), 1);
Date start=StringKit.toDate(request.getParameter("datestart"));
Date end=StringKit.toDate(request.getParameter("dateend"));
String start1=StringKit.toString(start);
String end1=StringKit.toString(end);

/* try{
  pageNo=Integer.parseInt(request.getParameter("pageNo"));
}catch(Exception e){} */

List<Student> list=service.search(pageNo, 20, name, tel, start, end);
int total=service.searchTotal(name, tel, start, end);
int pageTotal=total/20+(total%20==0?0:1);//总页数

%>
<p>
<form method="get" action="student.jsp">
 <input type="search" name="sname" value="<%=name%>" placeholder="用户名"/>
 <input type="search" name="tel" value="<%=tel%>" placeholder="手机号"/> 
 <input type="search" name="datestart" value="<%=start1%>" placeholder="入学时间起点"/> 
 <input type="search" name="dateend" value="<%=end1%>" placeholder="入学时间终点"/> 
           
 <input type="submit" value="search"/>
 </form>
</p>
<a href="addStudent.jsp">增加新生</a>

<table border="1" cellpadding="0" cellspacing="0">
<tr>
 <td>学号</td><td>姓名</td><td>手机号</td><td>年级</td>
 <td>性别</td><td>QQ</td><td>微信号</td><td>入学日期</td>
 <td>操作</td>
</tr>
<%

 for(Student s:list){
%>
 <tr>
  <td><%=s.getStuno()%></td><td><%=s.getSname() %></td><td><%=s.getTelephone() %></td>
  <td><%=s.getGradeid()%>-<%=s.getGname() %></td>
  <td><%=s.getSex() %></td><td><%=s.getQq() %></td><td><%=s.getWechat() %></td><td><%=s.getEnterdate()%></td>
  <td>
  	<a onclick="return window.confirm('真的要删除？')" href="delStudent.jsp?stuno=<%=s.getStuno()%>">删除</a>
 	&nbsp;
 	<a  href="studentUpdateServlet?stuno=<%=s.getStuno()%>">修改</a>
  </td>
 </tr>
<%} %>
</table>
<p align="center">
 <a href="student.jsp?pageNo=1&sname=<%=name%>&tel=<%=tel%>&datestart=<%=start1%>&dateend=<%=end1%>">首页</a>
<%
  if(pageNo>1){    
%>
 <a href="student.jsp?pageNo=<%=pageNo-1%>&sname=<%=name%>&tel=<%=tel%>&datestart=<%=start1%>&dateend=<%=end1%>">上一页</a>
 <%} %>
 <input type="number" min="1" name="go" style="width:30px" value="<%=pageNo%>"/>/<%=pageTotal%>
 <%
  if(pageTotal>pageNo){
 %>
 <a href="student.jsp?pageNo=<%=pageNo+1%>&sname=<%=name%>&tel=<%=tel%>&datestart=<%=start1%>&dateend=<%=end1%>">下一页</a>
 <%} %>
 <a href="student.jsp?pageNo=<%=pageTotal%>&sname=<%=name%>&tel=<%=tel%>&datestart=<%=start1%>&dateend=<%=end1%>">末页</a>
</p>
</body>
<script>
$(function(){
	 $("input[name=go]").keydown(function(event){ 
		 if(event.keyCode==13)//回车
		 {
			 if(this.value==""||isNaN(this.value)){
				 return false;
			 } 
			 window.location="student.jsp?pageNo="+$(this).val()+"&sname=<%=name%>&tel=<%=tel%>&datestart=<%=start1%>&dateend=<%=end1%>";
		 }
	 }).blur(function(){
		 if(this.value==""||isNaN(this.value)){
			 return false;
		 } 
		 window.location="student.jsp?pageNo="+$(this).val()+"&sname=<%=name%>&tel=<%=tel%>&datestart=<%=start1%>&dateend=<%=end1%>";
	 });
});
</script>
</html>